﻿// E-Book Copier
// Copyright (C) 2009 Chuan-Gen Fan
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Project: http://code.google.com/p/ebookcopier/
// Contact Author:
//    website: http://chuangen.name/
// e-mail/msn: chuangen@live.cn

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;

namespace EbookCopier
{
    /// <summary>
    /// 系统热键数据类。
    /// </summary>
    public class HotkeyValue
    {
        /// <summary>
        /// 修改键。
        /// </summary>
        public Keys Modifiers = Keys.None;
        /// <summary>
        /// 按键值。
        /// </summary>
        public Keys KeyCode = Keys.None;
        /// <summary>
        /// 初始化类 <see cref="HotkeyValue"/> 的新实例。
        /// </summary>
        /// <param name="modifiers">The modifiers.</param>
        /// <param name="keyCode">The key code.</param>
        public HotkeyValue(Keys modifiers, Keys keyCode)
        {
            this.Modifiers = modifiers;
            this.KeyCode = keyCode;
        }
        /// <summary>
        /// 已重载，返回“Ctrl+Alt+A”格式的字符串。
        /// </summary>
        /// <returns>类似“Ctrl+Alt+A”格式的字符串</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            if ((this.Modifiers & Keys.Control) != 0)
                sb.Append("Ctrl+");
            if ((this.Modifiers & Keys.Shift) != 0)
                sb.Append("Shift+");
            if ((this.Modifiers & Keys.Alt) != 0)
                sb.Append("Alt+");

            if (this.KeyCode != Keys.None)
                sb.Append((char)this.KeyCode);

            return sb.ToString();
        }
    }

    /// <summary>
    /// 公共类，将一些零散的常用的方法放置在这里。
    /// </summary>
    public partial class Common
    {
        /// <summary>
        /// 获取一个定位点（准星形状）的 GraphicsPath。
        /// </summary>
        /// <param name="point">点的坐标</param>
        /// <param name="length">控制点标线的长度。</param>
        /// <param name="pointR">控制点的显示半径。</param>
        /// <param name="neiR">中间空白圆半径。</param>
        /// <returns>GraphicsPath 实例。</returns>
        public static GraphicsPath GetFocusGraphicsPath(Point point, int length, int pointR, int neiR)
        {
            GraphicsPath path = new GraphicsPath();
            Matrix matrix = new Matrix();
            matrix.Translate(point.X, point.Y, MatrixOrder.Append);

            path.AddEllipse(new Rectangle(-pointR, -pointR, pointR * 2, pointR * 2));
            path.StartFigure();
            path.AddLine(new Point(-length, 0), new Point(-neiR, 0)); path.StartFigure();
            path.AddLine(new Point(length, 0), new Point(neiR, 0)); path.StartFigure();
            path.AddLine(new Point(0, -length), new Point(0, -neiR)); path.StartFigure();
            path.AddLine(new Point(0, length), new Point(0, neiR)); path.StartFigure();

            path.Transform(matrix);

            return path;
        }
    }
}
